import hashlib
from urllib.parse import quote

from curl_cffi import requests
import lxml
from util.headers import get_header
from util.time_stamp import get_time_stamp

root = get_header("https://huodong.taobao.com/")
cookie_tk = "79423e06676a57ad49a188f3d50b3b13_1762786774708"
t = get_time_stamp()
app_key = "12574478"
data = '{"url":"https://huodong.taobao.com/wow/a/act/tao/dailygroup/23509/24308/wupr?spm=tbpc.pc_sem_alimama/a.mid-banner.d1.487e2a895sUmCc&wh_pid=daily-575583&disableNav=YES&status_bar_transparent=true&bc_fl_src=tbsite_NOX36458&channelSrp=baiduSomama&clk1=dd222cc74365b037108b35a01faf17af&refpid=mm_26632258_3504122_32538762&bd_vid=11241546079259038342","cookie":"","device":"pc","backupParams":"device","usePrefetch":"false"}'
token = hashlib.md5(
    f"{cookie_tk.split('_')[0]}&{t}&{app_key}&{data}".encode()
).hexdigest()
url = f"https://h5api.m.taobao.com/h5/mtop.gaia.nodejs.gaia.arkact.handler/1.0/?jsv=2.7.2&appKey=12574478&t={t}&sign={token}&api=mtop.gaia.nodejs.gaia.arkact.handler&v=1.0&method=GET&dataType=jsonp&jsonpIncPrefix=PcHeadPrefetch&timeout=5000&type=jsonp&ttid=1%40tbwang_windows_1.0.0%23pc&callback=mtopjsonpPcHeadPrefetch1&data={quote(data, safe='(),:')}"

print(token, "token")
res = requests.get(
    url,
    headers=get_header("https://huodong.taobao.com/"),
    impersonate="chrome119",
    cookies={
        "_m_h5_tk": "79423e06676a57ad49a188f3d50b3b13_1762786774708",
        "_m_h5_tk_enc": "7f442cbd60b0e04c58940aab0cad2d96",
    },
)
print(res.text)
